package com.gmics.unifiq.adapter;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.gmics.android.R;
import com.gmics.unifiq.entity.Event;
import com.gmics.unifiq.entity.Group;
import com.gmics.unifiq.entity.OpenEvent;

public class OpenEventAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<OpenEvent> oeArr;

	public OpenEventAdapter(Context context, ArrayList<OpenEvent> oeArr) {
		this.context = context;
		this.oeArr = oeArr;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return oeArr.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return oeArr.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return oeArr.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View listView = new View(context);
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		listView = inflater.inflate(R.layout.event_list_item, null);

		ImageView img = (ImageView) listView
				.findViewById(R.id.event_grp_img);
		TextView title = (TextView) listView.findViewById(R.id.title_tv);
		TextView desc = (TextView) listView.findViewById(R.id.desc_tv);

		title.setText(oeArr.get(position).getName());
		desc.setText(oeArr.get(position).getDescription());
		
		String location = oeArr.get(position).getLocation();
		if (location.equals("NUS")) {
			img.setBackgroundResource(R.drawable.nus_logo);
		} else if (location.equals("NTU")) {
			img.setBackgroundResource(R.drawable.ntu_logo);
		} else if (location.equals("SMU")) {
			img.setBackgroundResource(R.drawable.smu_logo);
		} else if (location.equals("SIM")) {
			img.setBackgroundResource(R.drawable.sim_logo);
		}
	
		
		return listView;
	}

}